package zuoye;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Random;
import java.util.Set;


/*斗地主看牌有序*/
public class java7_22_8 {
	public static void main(String[] args) {
		ArrayList<String> poker=new ArrayList<String>();
		String[] colors={"♠","♣","♦","♥"};
		String[] numbers={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
		int[] data=new int[54];
		int[] arr1=new int[17];
		int[] arr2=new int[17];
		int[] arr3=new int[17];
		poker.add("大🤡");
		poker.add("小🤡");
		LinkedHashMap<Integer,String> map= new LinkedHashMap<>();
		int count=0;
		for(String number:numbers)
		{
			for(String color:colors){
				poker.add(color+number);
				map.put(count, color+number);
				count++;
			}
		}
		map.put(52, "大🤡");
		map.put(53, "小🤡");
		Set<Integer> keySet = map.keySet();
		Iterator<Integer> iterator = keySet.iterator();
		int count1=0;
		while(iterator.hasNext()){
			Integer next = iterator.next();
				data[count1]=next;
				count1++;
		}
		shuff(data);
		player p1=new player();p1.setName("老王");
		player p2=new player();p2.setName("老李");
		player p3=new player();p3.setName("老六");
		ArrayList<String> dipai =new ArrayList<String>();
		int num1=0,num2=0,num3=0;
		for(int i=0;i<54;i++){
			if(i>=51){
				dipai.add(map.get(data[i]));
			}else if(i%3==0){
				arr1[num1]=data[i];
				num1++;
			}
			else if(i%3==1){
				arr2[num2]=data[i];
				num2++;
			}
			else if(i%3==2){
				arr3[num3]=data[i];
				num3++;
			}
		}
		Arrays.sort(arr1);
		Arrays.sort(arr2);
		Arrays.sort(arr3);
		for(int i:arr1){
			p1.getPoker().add(map.get(i));
		}
		for(int i:arr2){
			p2.getPoker().add(map.get(i));
		}
		for(int i:arr3){
			p3.getPoker().add(map.get(i));
		}
		System.out.println(p1.getName()+"的牌"+p1.getPoker());
		System.out.println(p2.getName()+"的牌"+p2.getPoker());
		System.out.println(p3.getName()+"的牌"+p3.getPoker());
		System.out.println("底牌"+dipai);
	}

	private static void shuff(int[] data) {
		Random r =new Random();
		for(int i=data.length-1;i>0;i--){
			int num=r.nextInt(i+1);
			swap(data,num,i);
		}
	}

	private static void swap(int[] data, int i, int j) {
		int temp=data[i];
		data[i]=data[j];
		data[j]=temp;// TODO Auto-generated method stub
		
	}
}
